//package com.longteng.lesson2;
//
////import redis.clients.jedis.Jedis;
//
//import com.longteng.lesson2.util.TelnetSocket;
//import com.longteng.service.DubboTestService;
//import org.I0Itec.zkclient.ZkClient;
//import org.apache.zookeeper.WatchedEvent;
//import org.apache.zookeeper.Watcher;
//import org.apache.zookeeper.ZooKeeper;
//import org.junit.Test;
//import org.springframework.context.ApplicationContext;
//import org.springframework.context.support.ClassPathXmlApplicationContext;
//import org.springframework.util.StringUtils;
//
//import java.io.IOException;
//import java.net.URLDecoder;
//import java.util.*;
//
///**
// * Created by t
// * DATE : 2018/10/28 0028
// * TIME : 22:58
// * PROJECT : java-lesson2
// * PACKAGE : com.longteng.lesson2
// *
// * @author <a href="mailto:55324936@qq.com">taki</a>
// */
//public class FirstJava {
//    public static void main(String[] args) {
////        Jedis jedis =new Jedis("47.105.55.243",6379);
////        jedis.auth("longteng");
////        jedis.set("abc","aaa");
////        String s = jedis.get("abc");
////        System.out.println(s);
//    }
//
//    @Test
//    public void t(){
//        ApplicationContext context=new ClassPathXmlApplicationContext("consumer1.xml");
//        DubboTestService dubboTestService =(DubboTestService) context.getBean("dubboTestService");
//        String s =dubboTestService.sayHello("你好");
//        System.out.println(s);
//    }
//
//    @Test
//    public void generic(){
//        ApplicationConfig application = new ApplicationConfig();
//        application.setName("dubbo-consumer");
//        // 连接注册中心配置
//        RegistryConfig registry = new RegistryConfig();
//        registry.setAddress("zookeeper://47.105.55.243:20880");
//        //设置接口信息，和xml一样的
//        ReferenceConfig<GenericService> reference = new ReferenceConfig<GenericService>();
//        reference.setApplication(application);
//        reference.setRegistry(registry);
//        reference.setInterface("com.longteng.service.UserService");
//        reference.setGeneric(true); // 声明为泛化接口
//        reference.setUrl("dubbo://47.105.55.243:20880");
//        reference.setGroup("longteng");
//        reference.setVersion("1.0");
//        //从缓存里面拿接口
//        ReferenceConfigCache cache = ReferenceConfigCache.getCache();
//        GenericService genericService = cache.get(reference);
//        //设置参数类型
//        List<String> paramType =new ArrayList<>();
//        paramType.add("com.longteng.domain.User");
//        String[] strings = new String[paramType.size()];
//        paramType.toArray(strings);
//        //设置参数
//        Map map=new HashMap();
//        map.put("id",1);
//        List<Object> objectList =new ArrayList<>();
//        objectList.add(map);
//        Object[] objects =new Object[objectList.size()];
//        objectList.toArray(objects);
//        // 基本类型以及Date,List,Map等不需要转换，直接调用
//        Object result = genericService.$invoke("getUser",strings, objects);
//    }
//
//    @Test
//    public void telnet() throws Exception{
//        TelnetSocket telnetSocket=new TelnetSocket("47.105.55.243",20880);
//        String cmd ="invoke com.longteng.service.DubboTestService.sayHello(\"你好\")";
//        String s=  telnetSocket.send(cmd);
//        System.out.println(s);
//        String json="{\"id\":1}";
//        telnetSocket=new TelnetSocket("47.105.55.243",20880);
//        telnetSocket.setReadEncoding("GBK");
//        cmd="invoke com.longteng.service.UserService.getUser("+json+")";
//        s=telnetSocket.send(cmd);
////        s.replaceAll(".+}","");
//        s=s.substring(0,s.indexOf("elapsed"));
//        s = s.replace("dubbo>", "");
//        s =s.replace("elapsed:","");
//
//
////        List<String> methods = Arrays.asList(result.split("\r\n"));
////        for (int i = 0; i < methods.size(); i++) {
////            JsfData jsfData = new JsfData();
////            String m = methods.get(i);
////            String returnType = m.substring(0, m.indexOf(" "));
////            String methodName = m.substring(m.indexOf(" ") + 1, m.indexOf("("));
////            String paramType = m.substring(m.indexOf("(") + 1, m.indexOf(")"));
////            jsfData.setParamTypeValue(paramType);
////            String paramG = DataFormat.resolveParam(paramType);
////            paramType = paramType + "  例子:" + paramG + "";
////            jsfData.setParamType(paramType);
////            jsfData.setMethodName(methodName);
////            jsfData.setReturnType(returnType);
////            list.add(jsfData);
////        }
//        System.out.println(s);
//    }
//
//    @Test
//    public void zk() throws Exception{
//        ZkClient zkClient= new ZkClient("47.105.55.243:2181" );
//        //授权信息，不是必须的 zkClient.addAuthInfo("digest","longteng:123456".getBytes());
//
//        List<String> dubboNodeList=zkClient.getChildren("/dubbo/com.longteng.service.DubboTestService/providers");
//        for(String s:dubboNodeList){
//            String url = URLDecoder.decode(s,"UTF-8");
//            System.out.println(url);
//        }
//
//
////        ZooKeeper zookeeper = new ZooKeeper("47.105.55.243:2181", 2000,new A());
////        System.out.println(zookeeper.getState());
//        //授权信息，不是必须的zookeeper.addAuthInfo("digest","longteng:123456".getBytes());"
//
//    }
//
//
//
//}
